package cool.taomu.toolkit.test

import org.junit.jupiter.api.Test
import cool.taomu.toolkit.redisson.DistributedLock
import cool.taomu.toolkit.Taomu
import cool.taomu.toolkit.redisson.Param

class RedissonTest {

    @DistributedLock(key="order_lock_#orderId", waitTime=10, leaseTime=30)
    def void processOrder(@Param("orderId") String orderId) {
        System.out.println(Thread.currentThread().getName() + " Processing order: " + orderId);
        try {
            Thread.sleep(1000); // 模拟耗时操作
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }

    @Test
    def void testA() {
        var injector = Taomu.run();
        val service = injector.getInstance(RedissonTest)
        // 多线程测试
        for (var i = 0; i < 5; i++) {
            val int orderId = i;
            new Thread([service.processOrder("ORDER_" + orderId)]).start();
        }
    }

}
